import {canvas,ctx} from './canvas'
import Letters from './letter'
export default class draw extends Letters{
    constructor(){
        super()
        this.bgPic
        this.le
    }
    init(){
        this.le = []
        for(let i = 0; i < 5; i++){
            super.init()
            this.le.push(new draw())
        }
        this.x = 0
        this.y = 0
        this.bgPic = new Image()
        this.bgPic.src = './images/bg2.png'
        this.ImageDraw()
    }
    ImageDraw(){
        this.ctx.drawImage(this.bgPic,this.x,this.y,632,472)
        for(let i = 0; i < this.le.length; i++){
            this.le[i].leBackground()
            if(this.le[i].Ay >= 432){
                this.born(i)
            }  
        }
    }
    born(i){
        this.le[i].aLive = false
        this.le[i].ctx = ctx
        this.le[i].x = Math.floor(Math.random()*400) + 80
        this.le[i].y = 0
        this.le[i].Ax = this.le[i].x - 15
        this.le[i].Ay = this.le[i].y - 40
        this.le[i].aLive = true
        this.le[i].speed = Math.random()*0.017 + 2
        this.le[i].lett = super.letters()[Math.floor(Math.random()*48)]
        this.le[i].lePic = new Image()
        this.le[i].lePic.src = './images/苹果[图形].png'
        this.le[i].fColor = this.le[i].fColor
        let le_i = this.le[i]
        this.le.splice(i,1,le_i)
    }
}

